package se.webbzon.boltzmann.battle.strategy;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import se.webbzon.boltzmann.battle.battleaction.BattleAction;
import se.webbzon.boltzmann.battle.group.BattleGroup;
import se.webbzon.boltzmann.battle.object.npc.BattleNPC;
import se.webbzon.boltzmann.battle.round.BattleRound;
import se.webbzon.oschi01.worldarea.WorldArea;

public abstract class AbstractStrategy {
	
	// A collection of all listeners
	private final Collection<StrategyListener> listeners;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a new abstract strategy. **/
	public AbstractStrategy() {
		listeners = new ArrayList<StrategyListener>();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** This method is invoked when a strategy is started by a specific
	 * non-player battle character. **/
	public abstract void onBegin(	BattleRound round, WorldArea world, 
									List<BattleGroup> all, BattleNPC caster);
	
	/** Adds a strategy listener to this strategy. **/
	public boolean addListener(StrategyListener listener) {
		return listeners.add(listener);
	}
	
	/** Removes a strategy listener from this strategy. **/
	public boolean removeListener(StrategyListener listener) {
		return listeners.remove(listener);
	}
	
	/** Clears all listeners from this strategy. **/
	public void clearListeners() {
		listeners.clear();
	}
	
	/*============================================================
	Protected Methods
	============================================================*/
	
	/** Notifies all listeners that a battle action has been selected. **/
	protected void notifyListeners(BattleAction battleAction) {
		for (StrategyListener listener : listeners)
			listener.onSelect(this, battleAction);
	}

}
